package com.sb.utils;

import java.io.*;

/**
 * @author zhizunbao@wacai.com
 */
public class IOUtils {

    /**
     * 字符串转化成字节流
     *
     * @param str
     * @return
     */

    public static InputStream getStringInputStream(String str) {

        if (str != null && str.length() > 0) {
            try {
                ByteArrayInputStream stringInputStream = new ByteArrayInputStream(
                        str.getBytes());
                return stringInputStream;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    /**
     * 字符串转化成字符流
     *
     * @param str
     * @return
     */

    public static Reader getStringReader(String str) {
        if (str != null && str.length() > 0) {
            try {
                StringReader stringReader = new StringReader(str);
                return stringReader;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    public static String prompt(String prompt) {
        String str = null;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }

    public static String getInputStreamString(InputStream in)
            throws IOException {
        String context = org.apache.commons.io.IOUtils.toString(in);
        return context;
    }
}
